<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.liferay.portal.model.ListType"%>
<%@page import="com.liferay.portal.service.ListTypeServiceUtil"%>
<%@page import="com.liferay.portal.theme.ThemeDisplay"%>

<%@ page import="com.crossriver.crgis.cofo.util.ApplicationCofOConstants" %>
 
<%@ page import="com.crossriver.crgis.database.model.Application_C_of_O" %>
<%@page import="com.crossriver.crgis.database.model.Individual_Information"%>
<%@page import="com.crossriver.crgis.database.model.History_Of_Information"%>
<%@page import="com.crossriver.crgis.database.model.Contact_Information"%>
<%@page import="com.crossriver.crgis.database.model.Property_Information"%>
<%@page import="com.crossriver.crgis.database.model.Supporting_Document"%>
<%@page import="com.crossriver.crgis.database.service.persistence.Application_C_of_OUtil"%>
<%@page import="com.crossriver.crgis.database.model.Held_Plots"%>

<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ include file="/init.jsp"%>


<%

Application_C_of_O appl =
		(Application_C_of_O)request.getAttribute(
				ApplicationCofOConstants.APPL_C_OF_O_SESSION_ATTR);


Individual_Information indInfo = (Individual_Information)
			request.getAttribute(
				ApplicationCofOConstants.INDIVIDUAL_INFO_SESSION_ATTR);
Application_C_of_O applicatn = 
	Application_C_of_OUtil.findByPrimaryKey(indInfo.getApplicationId());

List<History_Of_Information> history = (List<History_Of_Information>)
					request.getAttribute(
						ApplicationCofOConstants.HISTORY_INFO_SESSION_ATTR);


Contact_Information indContInfo = (Contact_Information)
		request.getAttribute(
			ApplicationCofOConstants.IND_CONTACT_SESSION_ATTR);

Property_Information propInfo = (Property_Information)
			request.getAttribute(
				ApplicationCofOConstants.PROPERTY_INFO_SESSION_ATTR);


List<Supporting_Document> suppDocs = (List<Supporting_Document>)
			request.getAttribute(
				ApplicationCofOConstants.SUPP_DOC_INFO_SESSION_ATTR);

List<Held_Plots> heldPlots =(List<Held_Plots>) request.getAttribute("heldPlots");
int heldPlotsCounter = heldPlots.size();
%>


<liferay-portlet:actionURL name="finalSave" var="finalSave"></liferay-portlet:actionURL>

 <aui:form action="<%=finalSave.toString() %>" method="post" name="pickApplicationType_fm">
 <% String app = applicatn.getApplication(); %>
 <div id="main">
	<%
	if("certification".equalsIgnoreCase(app)){
	%>
	<h1>Application for Certificate Of Occupancy</h1>
	<%
	}else if("re-certification".equalsIgnoreCase(app)){
	%>
	<h1>Application for Re-Certificate Of Occupancy</h1>
	<%
	}else {
	%>
	<h1>Application for State Land</h1>
	<%
	}
	%>
	
	<div class="content">
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
			<tr>
			<td width="15%" valign="top">
				<aui:input name="applicationId" type="hidden" value="<%= appl.getApplicationId() %>"></aui:input>
				<aui:input name="buttonClicked" type="hidden" value=""></aui:input>
				<table width="100%" id="steps" cellpadding="0" cellspacing="0">
       		<tr><td valign="middle" align="center">STEP 1</td></tr>
       		<tr><td valign="middle" align="center">STEP 2</td></tr>
	        <tr><td valign="middle" align="center">STEP 3</td></tr>
          <tr><td valign="middle" align="center">STEP 4</td></tr>
          <tr><td valign="middle" align="center">STEP 5</td></tr>
          <tr><td valign="middle" align="center">STEP 6</td></tr>
          <tr><td valign="middle" align="center">STEP 7</td></tr>
          <tr><td valign="middle" align="center" class="current">STEP 8</td></tr>                               
       	</table>
			</td>
			<td width="85%" valign="top">
				<table width="100%" id="mainform">
					<tr>
						<td class="title" colspan="4">Application Summary</td>
					</tr>
					<tr>
						<td align="right" colspan="4">
						<hr>
						<aui:button type="button" value="Back" onClick="history.go(-1);return true;"></aui:button>    
						<aui:button type="submit" value="Final Save" onClick="setButtonClicked('btnSave');" ></aui:button>
            			<aui:button type="button" value="Cancel" onClick="confirmPost()"></aui:button>
						</td>
					</tr>

				<!-- Show this if this Re-CofO -->
				<%
				if (appl.getApplication().equalsIgnoreCase("RE-CERTIFICATION"))
				{
				%>
					<tr>
						<td colspan="4"><br>
							<liferay-portlet:actionURL var="editOldFileInfomation">
							  <liferay-portlet:param name="javax.portlet.action" value="editOldFileInfomation"></liferay-portlet:param>
							  <liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>">"></liferay-portlet:param>
							</liferay-portlet:actionURL>
							<span style="float: left; margin: 0; padding: 0" class="stitle">Old File Information</span> 
							<span style="float: right; margin: 0; padding: 0"><a href="<%= editOldFileInfomation %>">Edit</a></span><br>
							<hr>
						</td>
					</tr>
					
					<tr>
						<td colspan="4">
							<span class="dtitle">Old Certificate of Occupancy Number</span> 
							<span class="data"><%= appl.getOldCofONo()%></span>
						</td>
					</tr>
					<tr>
						<td colspan="4">
							<span class="dtitle">File Number</span> 
							<span class="data"><%= appl.getFileNo()%></span>
						</td>
					</tr>
				
				<%
				}
				%>
					
					<tr>
						<td colspan="4"><br>
							<liferay-portlet:actionURL var="editPersonalInformation">
							  <liferay-portlet:param name="javax.portlet.action" value="editPersonalInformation"></liferay-portlet:param>
							  <liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>">"></liferay-portlet:param>
							</liferay-portlet:actionURL>
							<span style="float: left; margin: 0; padding: 0" class="stitle">Personal Information</span> 
							<span style="float: right; margin: 0; padding: 0"><a href="<%= editPersonalInformation %>">Edit</a></span><br>
							<hr>
						</td>
					</tr>
					
					<tr>
						<td colspan="4">
							<span class="dtitle">Full Name</span> 
							<span class="data"><%= indInfo.getLastName().toUpperCase() %>, <%= indInfo.getFirstName() %> <%= indInfo.getMiddleName() %></span>
						</td>
					</tr>
					
					<tr>
						<td><br>
							<span class="dtitle">Sex</span> 
							<span class="data" > <%= indInfo.getGender() %></span>
						</td>
						
						
						<%
							SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");
							String formattedDOB = "";
							if (indInfo != null  && null != indInfo.getDateOfBirth()){
								formattedDOB = sdf.format(indInfo.getDateOfBirth());
							}
						%>
					
						<td colspan="2"><br>
							<span class="dtitle">Date Of Birth</span> 
							<span class="data"> <%= formattedDOB %> </span>
						</td>
						<td><br>
							<span class="dtitle">Occupation</span> 
							<span class="data" style="text-transform: uppercase"><%= indInfo.getOccupation() %></span>
						</td>
					</tr>
					
					<tr>
						<td width="25%"><br>
							<span class="dtitle">Marital Status</span> 
							<span class="data"><%= indInfo.getMaritalStatus() %></span>
						</td>
						<td width="25%"><br>
							<span class="dtitle">Religion</span> 
							<span class="data"><%= indInfo.getReligion() %></span>
						</td>
						<td width="25%"><br>
							<span class="dtitle">Education</span> 
							<span class="data"> <%= indInfo.getEducation() %></span>
						</td>
						<td width="25%"><br>
							<span class="dtitle"> No. Of Children</span> 
							<span class="data"><%= indInfo.getNoOfChildren() %></span>
						</td>
					</tr>
					
					<tr>
						<td><br>
							<span class="dtitle">Nationality</span> 
							<span class="data"><%= indInfo.getNationality() %></span>
						</td>
						<td><br>
							<!--  <span>State Of Origin</span> <span class="data"
								style="text-transform: uppercase">
									<%= indInfo.getStateOfOrigin() %>
								</span>-->
						</td>
						<td><br>
							<span class="dtitle">LGA</span> 
							<span class="data"> <%= indInfo.getLga()%> </span>
						</td>
						<td>&nbsp;
							
						</td>
					</tr>
					
						<liferay-portlet:actionURL var="editAddressInformation">
						  <liferay-portlet:param name="javax.portlet.action" value="editAddressInformation"></liferay-portlet:param>
						  <liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>">"></liferay-portlet:param>
						</liferay-portlet:actionURL>
						
					<tr>
						<td colspan="4"><br>
							<span style="float: left; margin: 0; padding: 0" class="stitle">Address Information</span> 
							<span style="float: right; margin: 0; padding: 0"><a href="<%= editAddressInformation %>">Edit</a></span><br>
							<hr>
						</td>
					</tr>
					
					<tr>
						<td colspan="4">
							<span class="dtitle">Contact Address</span> 
							<span class="data"> <%= indContInfo.getHouseNo() %>, <%= indContInfo.getAddressLine1() %><br><%= indContInfo.getAddressLine2() %>, </span>
						</td>
					</tr>
					
					<tr>
						<td><br>
							<span class="dtitle">City/Town</span> 
							<span class="data"><%= indContInfo.getCity()%></span>
						</td>
						<td><br>
							<span class="dtitle">State</span> 
							<span class="data"><%= indContInfo.getState() %></span>
						</td>
						<td><br>
							<span class="dtitle">Country</span> 
							<span class="data"><%= indContInfo.getCountry() %></span>
						</td>
						<td>&nbsp;</td>
					</tr>
					
					<tr>
						<td colspan="4"><br>
							<span class="dtitle">P.M.B Address</span> 
							<span class="data"><%= indContInfo.getPoBox() %></span>
						</td>
					</tr>
					
						<liferay-portlet:actionURL var="editContactInformation">
						  <liferay-portlet:param name="javax.portlet.action" value="editContactInformation"></liferay-portlet:param>
						  <liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>">"></liferay-portlet:param>
						</liferay-portlet:actionURL>
						
					<tr>
						<td colspan="4"><br>
							<span style="float: left; margin: 0; padding: 0" class="stitle">Contact Information</span> 
							<span style="float: right; margin: 0; padding: 0"><a href="<%= editContactInformation %>">Edit</a></span>
							<br><hr>
						</td>
					</tr>
					
					<tr>
						<td><br>
							<span class="dtitle">Mobile Phone</span> 
							<span class="data"><%= indContInfo.getPhoneMobile() %></span>
						</td>
						<td ><br>
							<span class="dtitle">Office Phone </span>
							<span class="data"><%= indContInfo.getPhoneOffice() %></span>
						</td>
						<td ><br>
							<span class="dtitle">Home Phone </span>
							<span class="data"><%= indContInfo.getPhoneHome() %></span>
						</td>
						<td>&nbsp;
							
						</td>
					</tr>
					
					<tr>
						<td colspan="4"><br>
							<span class="dtitle">Email Address</span> 
							<span class="data"><%= indContInfo.getEmailAddress() %></span>
						</td>
					</tr>
					
						<liferay-portlet:actionURL var="editApplicationHistory">
						  <liferay-portlet:param name="javax.portlet.action" value="editApplicationHistory"></liferay-portlet:param>
						  <liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>"></liferay-portlet:param>
						</liferay-portlet:actionURL>
					
					<tr>
						<td colspan="4"><br>
							<span style="float: left; margin: 0; padding: 0" class="stitle">Application History</span> 
							<span style="float: right; margin: 0; padding: 0"><a href="<%= editApplicationHistory %>">Edit</a></span><br>
							<hr>
						</td>
					</tr>
					
					<tr>
						<td colspan="4">
							<table id="tb" cellpadding="5">
								<tr class="tbtitle">
									<td>Application Number of Previous Application</td>
								</tr>
								<%
								for (int i =0; i<history.size(); i++){
									History_Of_Information hist  = history.get(i);
								%>
								<tr>
									<td>
									<%= hist.getOldApplicationId()%>
									</td>
								</tr>
								
								<%
								}
								%>
							</table>
						</td>
					</tr>
					
							<liferay-portlet:actionURL var="editPropertyInformation">
							  <liferay-portlet:param name="javax.portlet.action" value="editPropertyInformation"></liferay-portlet:param>
							  <liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>">"></liferay-portlet:param>
							</liferay-portlet:actionURL>
					
					<tr>
						<td colspan="4"><br>
							<span style="float: left; margin: 0; padding: 0" class="stitle">Property Information</span> 
							<span style="float: right; margin: 0; padding: 0"><a href="<%= editPropertyInformation %>">Edit</a></span><br>
							<hr>
						</td>
					</tr>
					<%
					if("stateland".equalsIgnoreCase(appl.getApplication())){
					%>
					<tr>
					<td ><br>
							<span class="dtitle">Plot Location:</span> </td>
						<td><span class="data"><%= propInfo.getLocationType() %></span>
						</td>
							
					</tr>
					<%
					if ("town".equalsIgnoreCase(propInfo.getLocationType())){
						
					%>
					<tr>
						<td ><br>
							<span class="dtitle">LGA</span> 
							<span class="data"> <%= propInfo.getLga() %></span>
						</td>
						<td><br>
							<span class="dtitle">Town</span> 
							<span class="data"><%= propInfo.getTown()%> </span>
						</td>
						<td><br>
							<span class="dtitle">Village</span> 
							<span class="data"> <%= propInfo.getVillage()%> </span>
						</td>
						<td>&nbsp;
							
						</td>
					</tr>
					<%
					}else
					{
					%>
					<tr>
						<td colspan="4"><br>
							<span class="dtitle">Plot Location</span>
							<span class="data"><%= propInfo.getLandLocation() %></span>
						</td>
					</tr>
					<%
					}
					%>
					
					
					<tr>
						<td colspan="4"><br>
							<span class="dtitle"> Give full description of plot for ease of identification supported with a sketch plan showing dimensions:<br> </span>
							<span class="data"><%= propInfo.getOtherUsefulInformation()%></span>  
						</td>
					</tr>
					
					
					<tr>
						<td ><br>
							<span class="dtitle">Length of term applied for</span> 
							<span class="data"> <%= propInfo.getTerm() %></span>
						</td>
						<td colspan="2"><br>
							<span class="dtitle">Estimated Cost of Development</span> 
							<span class="data">&#8358;<%= propInfo.getEstDevCost()%> </span>
						</td>
						<td><br>
						
						
						<%
							
							String formattedEstStartDate = "";
							if (propInfo != null  && null != propInfo.getEstStartDate()){
								formattedEstStartDate = sdf.format(propInfo.getEstStartDate());
							}
						%>
						
							<span class="dtitle">Time to start building</span> 
							<span class="data"> <%= formattedEstStartDate %> </span>
						</td>
					</tr>
					
					<tr>
						<td colspan="4">
						<br>
						<span class="dtitle">Particulars of Plots held by applicant:</span>
						<table border="thin solid #CCCCCC" cellpadding="0" cellspacing="0" id="tblparticulars">
							<tr>
								<td>Location</td>
								<td>Area(sq.m.)</td>
								<td>Is Plot Developed?</td>
								<td>Mode of Acquisition</td>
								<td>Registration Particulars</td>
							</tr>
			
			 
							<%
							
							for (int i = 0; i <heldPlotsCounter; i++) {
								Held_Plots held_plotItem = heldPlots.get(i);
								
							%>
							<tr id="<%= i %>">
								<td><%= held_plotItem.getLocation() %> </td>
							 	<td><%= held_plotItem.getArea() %></td>
							 	<td><%= held_plotItem.getDeveloped()%></td>
							 	<td><%=held_plotItem.getAcquisitionMode() %></td>
							 	<td><%= held_plotItem.getRegParticulars() %></td>
							</tr>
							
							<%
							}
							%>
						</table>
					</td>
				</tr>
					
				<tr>
					<td colspan="4">
						<br>
						<table id="tb" cellpadding="5">
							<tr class="tbtitle">
								<td>Land Use:</td>
								<td>Land Purpose:</td>
							</tr>
							<tr>
								<td><%= appl.getLandUseType() %></td>
								<td><%= appl.getLandUsePurpose()%></td>
							</tr>
						</table>
					</td>
				</tr>
					<%	
					}else{
					%>
				<tr>
					<td colspan="4">
						<table id="tb" cellpadding="5">
							<tr class="tbtitle">
								<td>Land Use:</td>
								<td>Land Purpose:</td>
							</tr>
							<tr>
								<td><%= appl.getLandUseType() %></td>
								<td><%= appl.getLandUsePurpose()%></td>
							</tr>
						</table>
					</td>
				</tr>
				
				<tr>
						<td ><br>
							<span class="dtitle">Property Type</span> 
							<span class="data"> <%= propInfo.getPropertyType()%></span>
						</td>
						<td><br>
							<span class="dtitle">Land Area</span> 
							<span class="data"><%= propInfo.getArea()%> <%= propInfo.getUom()%> </span>
						</td>
						<td><br>
							<span class="dtitle">Block No.</span> 
							<span class="data"> <%= propInfo.getBlockNo()%> </span>
						</td>
						<td>&nbsp;
							
						</td>
					</tr>
					
					<tr>
						<td colspan="2"><br>
							<span class="dtitle">Land Location</span> 
							<span class="data"><%= propInfo.getLandLocation()%> </span>
						</td>
						<td colspan="2"><br>
							<span class="dtitle">City/Town/Village</span> 
							<span class="data"><%= propInfo.getCity()%>, <%= propInfo.getState()%>, <%= propInfo.getCountry()%></span></td>
					</tr>
					
					<tr>
						<td colspan="4"><br>
							<span class="dtitle"> Please provide additional useful information that may assist the agency in processing your application.<br> </span>
							<span class="data"><%= propInfo.getOtherUsefulInformation()%></span>  
						</td>
					</tr>
					
					<tr>
					<%
						if("re-certification".equalsIgnoreCase(app)){
					%>
						<td colspan="4"><br>
						
						<%
							
							String formattedOrigCofODate = "";
							if (propInfo != null  && null != propInfo.getOrigCofODate()){
								formattedOrigCofODate = sdf.format(propInfo.getOrigCofODate());
							}
						%>
						
							<span class="dtitle">What is the date on the Original Certifiate of Occupancy (CofO)?</span>
							<span class="data"><%= formattedOrigCofODate%></span>
						</td>
					<%
					}
					%>
						
					</tr>
					<tr>
						<td colspan="4"><br>
							<span class="dtitle">Was the original allocation made to you?</span>
							<span class="data"><%= propInfo.getAllocationMadToYou()%></span> 
						</td>
					</tr>
					<tr>
						<td colspan="4"><br>
							<span class="dtitle">Do you have an assignment?</span>
							<span class="data"><%= propInfo.getAssignedToYou()%></span>
						</td>
					</tr>
					<tr>
						<td colspan="2"><br>
							<span class="dtitle">Specify Required Land Use</span> 
							<span class="data"><%= appl.getLandUseType()%></span>
						</td>
						<td colspan="2"><br>
							<span class="dtitle">Specify Purpose</span> 
							<span class="data"> <%= appl.getLandUsePurpose()%></span>
						</td>
					</tr>
					<%
					}
					%>
					
					
							<liferay-portlet:actionURL var="editSupportingDoc">
							  <liferay-portlet:param name="javax.portlet.action" value="editSupportingDoc"></liferay-portlet:param>
							  <liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>"></liferay-portlet:param>
							</liferay-portlet:actionURL>	
							
					<tr>
						<td colspan="4"><br>
							<span class="stitle">Uploads</span> 
							<span style="float: right; margin: 0; padding: 0"> <a href="<%= editSupportingDoc %>">Edit</a></span><br>
							<hr>
						</td>
					</tr>
					<tr>
						<td colspan="4"><span>Documents Uploaded</span></td>
					</tr>
					
					<tr>
						<td colspan="4">
							<table id="tb" cellpadding="5">
								<tr class="tbtitle">
									<td>Document Name</td>
									<td>File Name</td>
									<td>Document Type</td>
								</tr>
					
								<%
								for (int i = 0; i<suppDocs.size(); i++){
									Supporting_Document suppDoc = suppDocs.get(i);
								%>
								<tr>
									<td >
										<%= suppDoc.getDocumentName() %>
									</td>
									<td >
									 <%= suppDoc.getFileName() %>
										
									</td>
									<td >
									<%= suppDoc.getDocumentType() %>
									</td>
									
								</tr>
					
								<%
								}
								%>
							</table>
						</td>
					</tr>
					<tr>
						<td colspan="4" align="right"><br>
							<hr>
							<aui:button type="button" value="Back" onClick="history.go(-1);return true;"></aui:button>    
							<aui:button type="submit" value="Final Save" onClick="setButtonClicked('btnSave');" ></aui:button>
            	<aui:button type="button" value="Cancel" onClick="confirmPost()"></aui:button>
						</td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
	</div>
</div>
</aui:form>

<script type="text/javascript">
<!--
	function confirmPost()
	{
	var agree=confirm("Cancelling the process will delete the record you have entered into the portal for this application. Do you want to proceed?");
	if (agree){
		document.forms["<portlet:namespace/>deleteApplication_fm"].submit();
		return true ;
	}
	else{
		return false ;
	}
	}
//-->
</script>

<liferay-portlet:actionURL name="deleteApplication" var="deleteApplication"></liferay-portlet:actionURL>
 <aui:form action="<%=deleteApplication.toString() %>" method="post" name="deleteApplication_fm">
  	<aui:input name="applicationId" type="hidden" value="<%= appl.getApplicationId() %>"></aui:input>
 </aui:form>
 
 